package com.engine4cloud.tdf.supervision.controller.web;

import com.engine4cloud.tdf.common.core.constant.enums.CorAuditActionStatusEnum;
import com.engine4cloud.tdf.common.core.util.R;
import com.engine4cloud.tdf.common.log.annotation.SysLog;
import com.engine4cloud.tdf.supervision.dto.create.JzdxAuditAcceptCreateDTO;
import com.engine4cloud.tdf.supervision.dto.create.JzdxAuditAssignCreateDTO;
import com.engine4cloud.tdf.supervision.dto.create.JzdxAuditCreateDTO;
import com.engine4cloud.tdf.supervision.dto.result.EnumsTypeResultDTO;
import com.engine4cloud.tdf.supervision.service.JzdxAuditResultService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 矫正对象-审核-web
 *
 * @author wenjie
 * @date 2024-03-18 15:23:15
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/web/corrector/audit")
@Tag(description = "CorrectorAuditWeb", name = "矫正对象-审核-web")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class JzdxAuditResultWebController {

    @Resource
    private JzdxAuditResultService auditResultService;

    /**
     * 状态列表
     */
    @Operation(summary = "状态列表", description = "状态列表")
    @GetMapping("/all/status")
    public R<List<EnumsTypeResultDTO>> status() {
        List<EnumsTypeResultDTO> labelList = Arrays.stream(CorAuditActionStatusEnum.values())
                .map(state -> new EnumsTypeResultDTO(state.getType(), state.getStatus()))
                .collect(Collectors.toList());
        return R.ok(labelList);
    }

    /**
     * 县指派
     */
    @Operation(summary = "县指派", description = "县指派")
    @SysLog("县指派")
    @PutMapping("/assign")
    @PreAuthorize("@pms.hasPermission('corrector_assign')")
    public R<Boolean> assign(@Valid @RequestBody JzdxAuditAssignCreateDTO dto) {
        return R.ok(auditResultService.assign(dto));
    }

    /**
     * 所接收
     */
    @Operation(summary = "所接收", description = "所接收")
    @SysLog("所接收")
    @PutMapping("/accept")
    @PreAuthorize("@pms.hasPermission('corrector_accept')")
    public R<Boolean> accept(@Valid @RequestBody JzdxAuditAcceptCreateDTO dto) {
        return R.ok(auditResultService.accept(dto));
    }

    /**
     * 所拒绝
     */
    @Operation(summary = "所拒绝", description = "所拒绝")
    @SysLog("所拒绝")
    @PutMapping("/refuse")
    @PreAuthorize("@pms.hasPermission('corrector_refuse')")
    public R<Boolean> refuse(@Valid @RequestBody JzdxAuditCreateDTO dto) {
        return R.ok(auditResultService.refuse(dto));
    }
}